﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Base_Complementary_Encryption
{
    class Translate
    {
        public static async Task<string> EnglishAsync(string srcString)
        {
            HttpClient client = new HttpClient();//实例化对象
            var values = new Dictionary<string, string>();
            values.Add("i", srcString);
            values.Add("from", "en");
            values.Add("to", "zh-CHS");
            values.Add("smartresult", "dict");
            values.Add("client", "fanyideskweb");
            values.Add("salt", "16274470855592");
            values.Add("sign", "7fdf4e4c55c851d020930a7945e2bdcb");
            values.Add("Its", "1627447085559");
            values.Add("bv", "d192639f1f4a0c941e70905499fb80cc");
            values.Add("doctype", "json");
            values.Add("version", "2.1");
            values.Add("keyfrom", "fanyi.web");
            values.Add("action", "FY_BY_CLICKBUTTION");//设置参数
            var content = new FormUrlEncodedContent(values);//类型转换
            var response = await client.PostAsync("https://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule", content);//获取数据
            var responseString = await response.Content.ReadAsStringAsync(); //解析并读取数据
            string result = responseString.Split('[')[2].Split(':')[2].Split('"')[1];
            return result;
        }
    }
}
